<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" class="dom">
</body>
<script>
    // 防抖: n 秒后在执⾏该事件，若在 n 秒内被重复触发，则重新计时

    let dom =  document.querySelector('.dom')
    let timer = null

    dom.oninput = function(){
        if(timer){
            clearInterval(timer) //清除没有执行完的定时器 
        }
        timer = setTimeout(()=>{
            console.log(this.value);
        },2000)
    }

</script>
</html>